package com.jackson.passjava.question.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jackson.passjava.common.utils.PageUtils;
import com.jackson.passjava.common.utils.Query;
import com.jackson.passjava.question.dao.TypeDao;
import com.jackson.passjava.question.service.TypeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jackson.passjava.question.entity.TypeEntity;


/**
 * @author Liyuhang
 */
@Service("typeService")
public class TypeServiceImpl extends ServiceImpl<TypeDao, TypeEntity> implements TypeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        TypeEntity request = JSON.parseObject(JSON.toJSONString(params), TypeEntity.class);

        IPage<TypeEntity> page = this.page(
                new Query<TypeEntity>().getPage(params),
                new LambdaQueryWrapper<TypeEntity>()
                        .likeRight(StringUtils.isNotBlank(request.getType()),TypeEntity::getType,request.getType())
                        .ge(Objects.nonNull(request.getUpdateTime()),TypeEntity::getUpdateTime,request.getUpdateTime())
                        .ge(Objects.nonNull(request.getCreateTime()),TypeEntity::getCreateTime,request.getCreateTime())
        );

        return new PageUtils(page);
    }

}